<?php
/**
 * Created by PhpStorm.
 * User: hantian
 * Date: 2017/7/26
 * Time: 上午10:42
 */

namespace App\Admin\Extensions\Form;

use Encore\Admin\Form\Field;

class QiniuKindEditor extends Field
{

    public static $js = [
        '/qiniu-kindeditor/kindeditor-all.js',
        '/qiniu-kindeditor/lang/zh-CN.js',
    ];

    protected $view = 'admin.kindeditor';

    public function render()
    {
        $class = $this->getElementClass();
        $this->script = <<<EOT
        $.ajax({url: '/api/qiniu/token', async: false, success: function(data){
            token1 = data.uptoken;
            editor1 = KindEditor.create("#kindeditor-{$class[0]}",{
                resizeType : 1,
                minHeight:400,
                width:'100%',
                allowPreviewEmoticons: false,
                allowImageUpload:true,//允许上传图片
                allowFileManager:true, //允许对上传图片进行管理
                uploadJson : 'http://upload.qiniu.com/',
				filePostName : 'file',
				token : token1,
                fileManagerJson:'/kindeditor/php/file_manager_json.php',
                afterUpload: function(data){
                    console.log(data);
                }, //图片上传后，将上传内容同步到textarea中
                afterBlur: function(){this.sync();},   ////失去焦点时，将上传内容同步到textarea中
        
            });
        }});

EOT;
        return parent::render();
    }
}